package com.cxf.windex.base.util;

import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: cxf-mf
 * @description: 聚能小宝接口
 * @author: chenxf
 * @create: 2018-05-31 09:41
 **/
public class XiaoBaoUtil extends HttpUtil {

  private static RestTemplate restTemplate = new RestTemplate();
  public static final org.slf4j.Logger logger = LoggerFactory.getLogger(XiaoBaoUtil.class);


  public static Map saveApi(Map map,String uri,String userApi) {
    try {
      MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
      HttpEntity requestEntity = new HttpEntity(map, headers);
      ResponseEntity<Map> entity = restTemplate
          .exchange(uri+userApi, HttpMethod.POST, requestEntity, Map.class, new Object[0]);
      logger.debug("返回结果:" + entity.getBody());
      return entity.getBody();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return map;
  }



  public static void main(String[] args) {
     String uri = "http://localhost:8771";
     String userApi = "/platform_api/saveUser";
     String payApi = "/platform_api/savePay";
    Map paramMap = new HashMap<String, Object>();


//    paramMap.put("userid", "22222");
//    paramMap.put("name", "test1");
//    paramMap.put("token", "wx3f8cc71cec29b704");
//    saveApi(paramMap,uri,userApi);

    paramMap.put("userid", "22222");
    paramMap.put("payId", "111");
    paramMap.put("payM_money", "111");
    paramMap.put("totalMoney", "111");
    paramMap.put("name", "test1");
    paramMap.put("payCode", "certified");
    paramMap.put("payName", "认证费");
    paramMap.put("token", "wx3f8cc71cec29b704");
    paramMap.put("address", "浙江上海");
    saveApi(paramMap,uri,payApi);
  }
}
